package com.wondersgroup.fjzlpt.console.controller.rest.ksxx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.console.service.inter.ksxx.KsxxService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Map;

@RestController
@RequestMapping("/ksxx")
public class KsxxRestController {

	@Autowired
	private KsxxService ksxxService;
	
	@RequestMapping("/")
	public JSONArray queryKsxx(HttpServletRequest request)
	{
		Map map = RequestUtils.GetParameterMap(request);
		return ksxxService.queryListByPtjgidAndJb(map);
	}

	/**
	 * 查询机构科室详细信息
	 * @param request
	 * @return
	 */
	@RequestMapping("queryJgKsxxDetail")
	public JSONObject queryJgKsxxDetail(HttpServletRequest request){
		Map map = RequestUtils.GetParameterMap(request);
		return ksxxService.queryJgKsxxDetail(map);
	}

	/**
	 * 分页查询机构科室信息
	 * @param request
	 * @return
	 */
	@RequestMapping("queryPageKsxx")
	public JSONObject queryPageKsxx(HttpServletRequest request){
		String xzqh = QuickPrincipalUtils.getXzqhdm(request);
		Map map = RequestUtils.GetParameterMap(request);
		map.put("XZQHDM",xzqh);
		return ksxxService.queryPageKsxx(map);
	}

	/**
	 * 查询二级所有科室信息
	 * @param request
	 * @return
	 */
	@RequestMapping("querySecondJgKsxx")
	public JSONArray querySecondJgKsxx(HttpServletRequest request){
		Map map = RequestUtils.GetParameterMap(request);
		return ksxxService.querySecondJgKsxx(map);
	}

	/**
	 * 保存机构科室信息
	 * @param request
	 * @return
	 */
	@RequestMapping("saveKsxx")
	public JSONObject saveKsxx(HttpServletRequest request){
		Map map = RequestUtils.GetParameterMap(request);
		return ksxxService.saveKsxx(map);
	}

	@RequestMapping("/deleteJgKsxx")
	public JSONObject deleteJgKsxx(HttpServletRequest request){
		Map map = RequestUtils.GetParameterMap(request);
		return ksxxService.deleteJgKsxx(map);
	}
	
	/**
	 * 将科室信息导出到Excel
	 * @param request
	 * @return
	 */
	@RequestMapping("/downloadToExcel")
	public void downloadToExcel(HttpServletRequest request, HttpServletResponse response){
		String xzqh = QuickPrincipalUtils.getXzqhdm(request);
		Map map = RequestUtils.GetParameterMap(request);
		map.put("XZQHDM",xzqh);
		ksxxService.downloadToExcel(map, request, response);
	}
}
